package com.ericsson.entironment.sms;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.ericsson.common.xml.XMLException;
import com.ericsson.common.xml.XMLParser;




/**
 * 配参数的例子: <br>
 *  <br>
 * MsgInfo.registeredDelivery = 1,  <br>
 * MsgInfo.msgLevel = 1,  <br>
 * MsgInfo.serviceId = "websms", <br>
 * MsgInfo.feeUserType = 2,  <br>
 * MsgInfo.feeTerminalId = "0471*****", <br>
 * MsgInfo.tpPid = 0,  <br>
 * MsgInfo.tpUdhi = 0,  <br>
 * MsgInfo.msgFmt = 0, <br>
 * MsgInfo.msgSrc = "144305",  <br>
 * MsgInfo.feeType = "02",  <br>
 * MsgInfo.feeCode = "01",  <br>
 * MsgInfo.validTime = null,  <br>
 * MsgInfo.atTime = null,  <br>
 * MsgInfo.srcId = "0471*****", <br>
 * destTermianlId = new String[]{"1342********"},  <br>
 *  <br> <br>
 * 
 */

public class MsgInfo {

	  public static SimpleDateFormat format = new SimpleDateFormat("yyMMddhhmm");
	  private static MsgInfo info=null;
	  /**
	   * 是否要求返回状态确认报告 0: 不需要, 1:需要, 2:产生SMC话单<br>
	   * Unsigne Integer
	   */
	  public static int registeredDelivery;

	  /**
	   * 信息级别 <br>
	   * Unsigne Integer
	   */
	  public static int msgLevel;

	  /**
	   * 业务类型,是数字 字母和符号的组合  <br>
	   * Octet String
	   */
	  public static String serviceId;

	  /**
	   * 计费用户类型字段  <br>
	   *   0:对目的终端 MSISDN 计费, <br>
	   *   1:对源终端 MSISDN 计费, <br>
	   *   2:对SP计费, <br>
	   *   3表示本字段无效 对谁计费参见fee-terminal-id 字段 <br>
	   * Unsigne Integer
	   */
	  public static int feeUserType;

	  /**
	   * 被计费用户的号码(如本字节填空,则表示本字段无效,对谁计费参见 fee-usertype 字段,本字段与fee-usertype字段互斥) <br>
	   * Unsigne Integer
	   */
	  public static String feeTerminalId;

	  /**
	   * GSM 协议类型  <br>
	   * Unsigne Integer
	   */
	  public static int tpPid;

	  /**
	   * GSM 协议类型, 仅使用1位,右对齐  <br>
	   * Unsigne Integer
	   */
	  public static int tpUdhi;

	  /**
	   * 信息格式  <br>
	   * 0:ASC II 串, <br>
	   * 3:短信写卡操作, <br>
	   * 4:二进制信息, <br>
	   * 8:UCS2编码,  <br>
	   * 15:含GB汉字  <br>
	   * Unsigne Integer
	   */
	  public static int msgFmt;

	  /**
	   * 信息内容来源(sp-id)  <br>
	   * Octet String
	   */
	  public static String msgSrc;

	  /**
	   * 计费类别  <br>
	   * 01:对计费用户号码免费,  <br>
	   * 02:对计费用户号码按条计信息费,  <br>
	   * 03:对计费用户号码按包月收取信息费,  <br>
	   * 04:对计费用户号码的信息费封顶,  <br>
	   * 05:对计费用户号码的收费是由sp实现 <br>
	   * Octet String
	   */
	  public static String feeType;

	  /**
	   * 资费代码(以分为单位)  <br>
	   * Octet String
	   */
	  public static String feeCode;

	  /**
	   * 存活有效期  <br>
	   * Octet String
	   */
	  public static Date validTime;

	  /**
	   * 定时发送时间  <br>
	   * Octet String
	   */
	  public static Date atTime;
	
	  /**
	   * 源号码  <br>
	   * Octet String
	   */
	  public static String srcId;

	  /**
	   * 接受信息的用户数量(小于100个用户)  <br>
	   * Unsigne Integer
	   */
	  public static int destusrTl;

	  /**
	   * 信息长度(msg-fmt 值为0时:<160个字节, 其他<=140个字节)  <br>
	   * Unsigne Integer
	   */
	  public static int msgLength;


	
	private MsgInfo() throws XMLException {

		XMLParser parser=new XMLParser(this.getClass().getResource("/CMPPSubmit.xml").getPath().replaceAll("%20"," "));
		this.destusrTl =  Integer.parseInt(parser.getElement("CMPPSubmit[0].destusr-tl[0]"));
		this.feeCode =  parser.getElement("CMPPSubmit[0].feecode[0]");
		this.feeTerminalId =  parser.getElement("CMPPSubmit[0].fee-terminal-id[0]");
		this.feeType =  parser.getElement("CMPPSubmit[0].feetype[0]");
		this.feeUserType = Integer.parseInt( parser.getElement("CMPPSubmit[0].fee-usertype[0]"));
		this.msgFmt =  Integer.parseInt(parser.getElement("CMPPSubmit[0].msg-fmt[0]"));
		this.msgLength =  Integer.parseInt(parser.getElement("CMPPSubmit[0].msg-length[0]"));
		this.msgLevel =  Integer.parseInt(parser.getElement("CMPPSubmit[0].msg-level[0]"));
		this.msgSrc =  parser.getElement("CMPPSubmit[0].msg-src[0]");
		this.registeredDelivery =  Integer.parseInt(parser.getElement("CMPPSubmit[0].registered-delivery[0]"));
		this.serviceId =  parser.getElement("CMPPSubmit[0].service-id[0]");
		this.srcId =  parser.getElement("CMPPSubmit[0].src-id[0]");
		this.tpPid =  Integer.parseInt(parser.getElement("CMPPSubmit[0].tp-pid[0]"));
		this.tpUdhi =  Integer.parseInt(parser.getElement("CMPPSubmit[0].tp-udhi[0]"));

		if(parser.getElement("CMPPSubmit[0].valid-time[0]") == null || parser.getElement("CMPPSubmit[0].valid-time[0]").equals("")){
			this.validTime = null;
		}else{
			this.validTime = new Date(Long.parseLong(parser.getElement("CMPPSubmit[0].valid-time[0]"))+System.currentTimeMillis());
		}
		
		if(parser.getElement("CMPPSubmit[0].at-time[0]") == null || parser.getElement("CMPPSubmit[0].at-time[0]").equals("")){
			this.atTime = null;
		}else{
			this.atTime = new Date(Long.parseLong(parser.getElement("CMPPSubmit[0].at-time[0]"))+System.currentTimeMillis());
		}
		
	}



	public static synchronized  MsgInfo getInstance() throws XMLException
	{
		if (info==null)
			info=new MsgInfo();
		return info;
	}

}
